//
//  MusicListCell.m
//  Auditory
//
//  Created by 寒竹子 on 15/5/4.
//  Copyright (c) 2015年 寒竹子. All rights reserved.
//

#define KBorder 10.0f
#define Head_W  55.0f

#import "MusicListCell.h"
#import "songListModel.h"
#import "UIImageView+WebCache.h"
#import "Globle.h"

@interface MusicListCell()

@end

@implementation MusicListCell
{
    songListModel * _model;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _header = [[UIImageView alloc] init];
        _header.clipsToBounds = YES;
        _header.layer.cornerRadius = Head_W / 2.0f;
        _header.layer.borderWidth = 3.0f;
        _header.layer.borderColor = RGB(19, 185, 230, 1.0f).CGColor;
        [self.contentView addSubview:_header];
        
        // 名称
        _songNameLabel = [[UILabel alloc] init];
        _songNameLabel.font = TextFont(16.0f);
        _songNameLabel.textColor = RGB(100, 100, 100, 1.0f);
        
        [self.contentView addSubview:_songNameLabel];
        
        // 演唱者
        _songnerLabel = [[UILabel alloc] init];
        _songnerLabel.font = TextFont(14.0f);
        _songnerLabel.textColor = RGB(160, 160, 160, 1.0f);
        [self.contentView addSubview:_songnerLabel];
    }
    
    return self;
}

- (void)setModel:(songListModel *)model
{
    _model = model;
    
    CGFloat headX = KBorder;
    CGFloat headY = KBorder;
    
    _header.frame = CGRectMake(headX, headY, Head_W, Head_W);
    [_header sd_setImageWithURL:[NSURL URLWithString:_model.icon] placeholderImage:[UIImage imageNamed:@"musicHeader"]];
    
    CGFloat nameX = CGRectGetMaxX(_header.frame) + KBorder;
    CGFloat nameY = KBorder * 2.0f;
    CGFloat nameWidth = self.frame.size.width - nameX - KBorder;
    _songNameLabel.frame = CGRectMake(nameX, nameY, nameWidth, 30.0f);
    _songNameLabel.text = _model.title;
    
    if ([Globle sharedGloble].isHasResource && _indexPath.row == [Globle sharedGloble].playingIndex) {
        self.backgroundColor = [UIColor orangeColor];
    }else {
        self.backgroundColor = [UIColor whiteColor];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    _songNameLabel.textColor = RGB(100, 100, 100, 1.0f);
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    
    _songNameLabel.textColor = RGB(100, 100, 100, 1.0f);
}

@end
